package com.example.yjhuser.controller;

import com.example.yjhuser.entity.Comment;
import com.example.yjhuser.service.CommentService;
import com.yc.yjh.entity.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    CommentService commentService;

    @GetMapping("/video/byId")
    public Result getAllVideoCommentById(@RequestParam("id") String id){
        String type="1";
        final List<Comment> comment = commentService.getAllCommentByIdAndType(id, type);
        return Result.success("OK",comment);
    }

    @GetMapping("/tz/byId")
    public Result getAllTiezCommentById(@RequestParam("id") String id){
        String type="2";
        final List<Comment> comment = commentService.getAllCommentByIdAndType(id, type);
        return Result.success("OK",comment);
    }

    @GetMapping("/tz/byuId")
    public Result getAllTiezCommentByUid(@RequestParam("id") String uid){
        String type="2";
        final List<Comment> comment = commentService.getAllCommentByIdAndType(uid, type);
        return Result.success("OK",comment);
    }


    @PostMapping("/set")
    public Result setComment(@RequestBody Comment comment){
        final int i = commentService.setComment(comment);
        if (i>0){
            return Result.success("成功发布评论!");
        }else {
            return Result.error("发布失败，请稍后再试");
        }
    }

    @GetMapping("/del")
    public  Result setComment(@RequestParam("id") String id){
        int i = commentService.delComment(id);
        if (i>0){
            return Result.success("删除评论成功!");
        }else {
            return Result.error("业务繁忙，请稍后再试!");
        }
    }

    @GetMapping("/allByuid")
    public Result getAllCommentByUid(String id){
        return Result.success("OK",commentService.getAllCommentByUserId(id));
    }

}
